package com.base.cn.platform.os.controller.web.classes.personal;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.entity.classes.topic.type.ClassesTopicType;
import com.base.cn.platform.os.service.course.classes.ClassesService;
import com.base.cn.platform.os.service.course.classes.member.ClassesMemberService;
import com.base.cn.platform.os.service.course.classes.topic.type.ClassesTopicTypeService;
import com.base.cn.platform.os.service.manage.user.user.CusUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 我的班级
 *
 * @author SK
 * @since 2018-05-28
 */
@Controller
public class WebClassesPersonalController extends WebBaseController {

    @Autowired
    private ClassesService classesService;
    @Autowired
    private ClassesMemberService classesMemberService;
    @Autowired
    private CusUserService cusUserService;
    @Autowired
    private ClassesTopicTypeService   classesTopicTypeService;

    /**
     * 我的班级首页
     */
    @RequestMapping("/web/uc/classes/personal/index")
    public String index(HttpServletRequest request,Model model) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        boolean is = classesMemberService.checkNoJoinClassesMember(userId);
        model.addAttribute("notJoinClass",is);
        Map<String,Object> cusUser = cusUserService.userInfo(userId,false,false,false,false,false,false,false);
        model.addAttribute("cusUser",cusUser);
        Map<String,Object> statistics = classesMemberService.classesMemberStatistics(userId);
        model.addAttribute("statistics",statistics);
        //话题分类统计
        List<Map<String, Object>> classesTypeNum = classesTopicTypeService.getClassesTypeNum(null, userId);
        model.addAttribute("topicTypeNum",classesTypeNum);
        return resultPage("/classes/personal/personal-classes");
    }

    /**
     * 加载与用户相关的班级
     *
     * @param currentPage 第N页
     */
    @RequestMapping("/web/classes/personal/ajaxClassesList")
    public String listClassPersonal(Model model,
                                    HttpServletRequest request,
                                    @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String, Object> dataMap = classesService.findClassesPersonalListPage(userId, currentPage, 9);
        model.addAttribute("dataMap", dataMap);
        return resultPage("/classes/personal/ajax-classes-personal-list");
    }

}
